Skip to content

Stabilize is_symlink() for Metadata and Path - #89677

Merged
bors merged 3 commits into
rust-lang:masterfrom
maxwase:is-symlink-stabilization
Oct 31, 2021
Merged

Stabilize is_symlink() for Metadata and Path#89677
bors merged 3 commits into
rust-lang:masterfrom
maxwase:is-symlink-stabilization

Conversation

@maxwase

@maxwase maxwase commented Oct 8, 2021

Copy link
Copy Markdown
Contributor

I'm not fully sure about since version, correct me if I'm wrong

Needs update after stabilization: cargo-test-support

Linked issue: #85748

@rust-highfive

ghost commented Oct 8, 2021

Copy link
Copy Markdown
Contributor

r? @kennytm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 8, 2021
@jonas-schievink jonas-schievink added relnotes Marks issues that should be documented in the release notes of the next release. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 8, 2021
@joshtriplett joshtriplett added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 9, 2021
@joshtriplett

ghost commented Oct 9, 2021

Copy link
Copy Markdown
Member

@rfcbot merge

@rfcbot

ghost commented Oct 9, 2021

Copy link
Copy Markdown

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 9, 2021
@nagisa

ghost commented Oct 9, 2021

Copy link
Copy Markdown
Member

I'm not fully sure about since version, correct me if I'm wrong

Its accurate provided this PR lands before sometime in October 21st.

@Kixunil

ghost commented Oct 9, 2021

Copy link
Copy Markdown
Contributor

Shouldn't this return Result in the spirit of try_exists? Or is it considered too inconsistent given existing methods return bool?

@joshtriplett

ghost commented Oct 10, 2021

Copy link
Copy Markdown
Member

@Kixunil Good catch!

@rfcbot concern should-return-result

@maxwase

ghost commented Oct 10, 2021

Copy link
Copy Markdown
Contributor Author

Shouldn't this return Result in the spirit of try_exists? Or is it considered too inconsistent given existing methods return bool?

I don't think it should. There are is_dir and if_file methods with this signature (stable since 1.5.0). This question is also discussed in #76487 and #83186.

Personally, I think it would be inconvenient to return Result in this method, but it might be useful to have try_exists_symlink to some extend, but to what extent?

For now it works well playground

@Kixunil @joshtriplett

@Kixunil

ghost commented Oct 10, 2021

Copy link
Copy Markdown
Contributor

I personally think that bools are footguns here - easy to forget about the case that syscall may fail. It does make sense on Metadata, which already performed such check though.

The question is will we deprecate exists&co eventually? If so stabilizing this just to deprecate it later doesn't sound well.

? is one-character operator and if you can't be bothered to adjust error types because you don't believe it will ever be error, just unwrap is better for debugging.

@joshtriplett

ghost commented Oct 10, 2021

Copy link
Copy Markdown
Member

I agree that on Metadata we can just return bool. On Path, I think we should return a result.

@maxwase

ghost commented Oct 11, 2021

Copy link
Copy Markdown
Contributor Author

@joshtriplett, Wouldn't it be illogical to have is_dir() -> bool and is_file() -> bool, but is_symlink() -> Result<bool, Error>?

I see 3 ways to solve this:

  1. Deprecate is_dir and is_file -> bool signatures and replace these with try_is_.... This will brake A LOT of code and make these methods so inconviniet to use due to error handling. These methods alwo used in functions that retuns a lot of types of errors, so you can't just use ?, also you can't use .unwrap() because it will be strange to see in production code, so you will use .unwrap_or(false), as currently implemented. A programmer who wants to handle methadata error can do it by himself.
  2. Accept this PR to comlete a "method hole" and continue thinking about it.
  3. Accept this PR and open new, not deprecating old methods. New PR will add try_is..., so it will be convinient to use for everyone.

@Kixunil

ghost commented Oct 11, 2021

Copy link
Copy Markdown
Contributor

make these methods so inconviniet to use

It's only inconvenient if you intend to write dubious code that silently ignores possibly serious issue. Rust is generally designed to not ignore errors.

also you can't use .unwrap() because it will be strange to see in production code, so you will use .unwrap_or(false)

If you can't use unwrap() in production you can't use unwrap_or(false) either, that's just silently swallowing possibly serious issue. Actually I'd rather use unwrap() in production than implicit unwrap_or(false) because that way I at least learn that something is wrong. Silent errors are super-nightmare of debugging.

Given that it'd be strange that there are methods with is_ that return bool it makes most sense to me to add remaining try_ methods and rename this one to begin with try_.

@maxwase

ghost commented Oct 11, 2021

Copy link
Copy Markdown
Contributor Author

@Kixunil I agree with you. So we change is_symlink to try_is_symlink and add in new PR try_ versions for is_file and is_dir? What about deprecation?

@nagisa

ghost commented Oct 11, 2021

Copy link
Copy Markdown
Member

Does try_is_* provide enough value over try { metadata()?.is_*() } to warrant the method? Not to mention that metadata version naturally directs users towards reuse of the metadata query in case they want to check for multiple things (e.g. symlink || file)

@Kixunil

ghost commented Oct 11, 2021

Copy link
Copy Markdown
Contributor

@maxwase that's what I believe would be the best. Not sure about deprecation but I would be in favor of it once try_* methods are in std long enough.

@nagisa sure, I think simple method is much more likely to stabilize than try { } block. ;)

@nagisa

ghost commented Oct 11, 2021

Copy link
Copy Markdown
Member

try is quite likely addition to the language AFAIK. If we stabilized try within a year's time, is the value provided by such a method over this period really all that high to warrant us dealing with its existence for the remaining lifetime of the language?


My personal opinion is that we should either stabilize Path::is_symlink as is for consistency with Path::is_file and Path::is_dir; or we shouldn't add any function to Path at all, direct users towards metadata and wait for try {} to improve ergonomics somewhat.

@yaahc

ghost commented Oct 11, 2021

Copy link
Copy Markdown
Member

I think I'm in agreement with @nagisa and @maxwase. I don't believe it would be a good idea to add a Result returning function here to Path directly. All of the related methods on Path have documentation pointing users towards metadata() when one wants to handle errors explicitly, separate from the boolean return from is_file and friends. I think in this case we should be prioritizing internal consistency with other related Path APIs over fears of error-proneness. If we think that these helper APIs that return bools are particularly error-prone then that is a separate issue and we should deprecate them and universally push users towards metadata and symlink_metadata, not introduce a third way to call the same API.

That said, while all of the other methods on Path have a note indicating what API to use when explicit error handling is required, is_symlink does not. I would like to see a similar section added to the documentation for is_symlink to point users towards the fs::symlink_metadata method when explicit error handling is required.

Comment thread library/std/src/path.rs
@joshtriplett

ghost commented Oct 12, 2021

Copy link
Copy Markdown
Member

I do personally feel that we should have try versions of these methods, but that doesn't need to be a blocker here.

@rfcbot resolved should-return-result

Co-authored-by: Jane Lusby <jlusby42@gmail.com>
@maxwase
maxwase requested a review from yaahc October 12, 2021 09:33
@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Oct 12, 2021
@rfcbot

ghost commented Oct 22, 2021

Copy link
Copy Markdown

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@joshtriplett

ghost commented Oct 30, 2021

Copy link
Copy Markdown
Member

@bors r+

@bors

ghost commented Oct 30, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 3e0360f has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 30, 2021
@bors
bors merged commit 15a0cdd into rust-lang:master Oct 31, 2021
@rustbot rustbot added this to the 1.58.0 milestone Oct 31, 2021
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Nov 11, 2021
@maxwase
maxwase deleted the is-symlink-stabilization branch December 2, 2021 16:26
@WhyNotHugo

ghost commented Dec 6, 2021

Copy link
Copy Markdown

I don't fully grasp the state of this feature; isn't it available as of 1.57?

I'm getting an error indicating that it's unstable:

error[E0658]: use of unstable library feature 'is_symlink'
  --> src/main.rs:82:22
   |
82 |         if home_path.is_symlink() {
   |                      ^^^^^^^^^^
   |
   = note: see issue #85748 <https://github.com/rust-lang/rust/issues/85748> for more information

error[E0658]: use of unstable library feature 'is_symlink'
  --> src/main.rs:87:26
   |
87 |     } else if !home_path.is_symlink() {
   |                          ^^^^^^^^^^
   |
   = note: see issue #85748 <https://github.com/rust-lang/rust/issues/85748> for more information

@ChrisDenton

ghost commented Dec 6, 2021

Copy link
Copy Markdown
Member

If you look at the sidebar you should see a "milestone" tag. This says it'll be stable in 1.58.

@WhyNotHugo

ghost commented Dec 6, 2021

Copy link
Copy Markdown

Ah, that completely slipped past me, thanks!

@ChrisDenton

ghost commented Dec 6, 2021

Copy link
Copy Markdown
Member

No worries. It's easy to miss if you don't know to look for it.

@maxwase

ghost commented Dec 7, 2021

Copy link
Copy Markdown
Contributor Author

I don't fully grasp the state of this feature; isn't it available as of 1.57?

I'm getting an error indicating that it's unstable:

error[E0658]: use of unstable library feature 'is_symlink'
  --> src/main.rs:82:22
   |
82 |         if home_path.is_symlink() {
   |                      ^^^^^^^^^^
   |
   = note: see issue #85748 <https://github.com/rust-lang/rust/issues/85748> for more information

error[E0658]: use of unstable library feature 'is_symlink'
  --> src/main.rs:87:26
   |
87 |     } else if !home_path.is_symlink() {
   |                          ^^^^^^^^^^
   |
   = note: see issue #85748 <https://github.com/rust-lang/rust/issues/85748> for more information

I don't understand this too. Stable attribute is 1.57 in master, but milestone is 1.58 here. Also this PR was not mentioned in release list
@joshtriplett, can you please explain?

@kennytm

ghost commented Dec 7, 2021

Copy link
Copy Markdown
Member

it means the #[stable] version property is wrongly tagged 🤷

@maxwase

ghost commented Dec 7, 2021

Copy link
Copy Markdown
Contributor Author

it means the #[stable] version property is wrongly tagged 🤷

Should I replace it in new PR?

@kennytm

ghost commented Dec 9, 2021

Copy link
Copy Markdown
Member

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api [DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.